package com.employeemanage.controller;

import com.employeemanage.domain.bean.TblPurchase;
import com.employeemanage.domain.resp.PageResult;
import com.employeemanage.domain.resp.Result;
import com.employeemanage.domain.vo.PurchaseAddResponseVo;
import com.employeemanage.domain.vo.PurchaseAddVo;
import com.employeemanage.domain.vo.PurchaseListVo;
import com.employeemanage.service.TblPurchaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 采购记录 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-07-05
 */
@RestController
@RequestMapping("/product/purchase")
@Api(tags = "进货管理")
@Validated
public class TblPurchaseController {

    @Autowired
    private TblPurchaseService purchaseService;

    /**
     * 获取进货记录列表
     */
    @PostMapping("/list")
    @ApiOperation("获取进货记录列表")
    public Result<PageResult<TblPurchase>> getPurchaseList(@Valid @RequestBody PurchaseListVo purchaseListVo) {
        try {
            PageResult<TblPurchase> result = purchaseService.getPurchaseList(purchaseListVo);
            return Result.success(result);
        } catch (Exception e) {
            return Result.fail("获取进货记录列表失败：" + e.getMessage());
        }
    }

    /**
     * 新增进货记录
     */
    @PostMapping("/add")
    @ApiOperation("新增进货记录")
    public Result<PurchaseAddResponseVo> addPurchase(@Valid @RequestBody PurchaseAddVo purchaseAddVo) {
        try {
            PurchaseAddResponseVo result = purchaseService.addPurchase(purchaseAddVo);
            return Result.success(result);
        } catch (Exception e) {
            return Result.fail("新增进货记录失败：" + e.getMessage());
        }
    }
}
